package com.starking.wxx.thread;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @描述: 线程池
 * @文件名: ThreadFactory.java
 * @创建人: wangxinxin
 * @创建时间: 2018/11/1
 * @修改人: wangxinxin
 * @修改备注: <br/>
 * <p>
 */
public class ThreadFactory {

    //线程池
    private static final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10, 10, 0L,
            TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(5000), new java.util.concurrent.ThreadFactory() {
        @Override
        public Thread newThread(Runnable r) {
//            return new Thread(r, r.getClass().getSimpleName());
            return new Thread(r);
        }
    }, new RejectedExecutionHandler() {
        @Override
        public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
        }
    });

    /**
     * 执行一个线程
     * @param task
     */
    public static void execute(Runnable task) {
        threadPoolExecutor.execute(task);
    }

}
